package com.fram.controller.admin;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.fram.bean.admin.circle.request.ResourceCircleRequest;
import com.fram.bean.sys.PageBean;
import com.fram.bean.sys.ResponseMsg;
import com.fram.common.canstant.ErrCode;
import com.fram.common.exception.ProAffairException;
import com.fram.common.exception.ProException;
import com.fram.common.util.PublicMethod;
import com.fram.common.util.apiversion.ApiVersion;
import com.fram.entity.ResourceCircle;
import com.fram.service.admin.CircleService;

@RestController
@RequestMapping("/admin/{version}/auth/resourcecircle")
public class CircleController {
	//
	private static Logger LOG = LoggerFactory.getLogger(CircleController.class);
	@Autowired
	private CircleService circleService;

	/****/
	@ApiVersion(1.0)
	@RequestMapping(value = "/list", method = RequestMethod.POST)
	private ResponseMsg list(@RequestBody PageBean<ResourceCircleRequest> request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			msg.setData(circleService.list(request));
		} catch (ProException e) {
			LOG.error("-种植圈全部展示->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-种植圈全部展示->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}

	@ApiVersion(1.0)
	@RequestMapping(value = "/update", method = RequestMethod.POST)
	private ResponseMsg update(@RequestBody ResourceCircle request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			circleService.update(request);
		} catch (ProAffairException e) {
			LOG.error("-种植圈修改出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-种植圈修改异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
}
